package org.peoples;

import java.util.Iterator;
import java.util.List;
import java.util.TimerTask;

import org.peoples.clients.ClientPool;
import org.peoples.rooms.Room;
import org.peoples.rooms.RoomPool;
import org.red5.server.api.IClient;

public class CheckStatus extends TimerTask {
	
	private Application app;
	private ClientPool clients;
	private RoomPool rooms;
	
	public CheckStatus(Application app) {
		this.app = app;
		this.clients = ClientPool.getInstance();
		this.rooms = RoomPool.getInstance();
	}
	
	public void run() {
		
		System.out.println("[CHECK STATUS] Running status check:");
		System.out.println("====");
		Iterator<IClient> client_itr = clients.getAllClients().iterator();
		while (client_itr.hasNext()) {
			IClient client = client_itr.next();
		}
		
		System.out.println("[CHECK STATUS] Clients connected: " + clients.size());
		System.out.println("[CHECK STATUS] User -> IClient Mappings: " + clients.toString());
		System.out.println("[CHECK STATUS] IClients: " + app.getClients().toString());
		
		System.out.println("----");
		System.out.println("[CHECK STATUS] Rooms open: " + rooms.getAllRooms().size());

		Iterator<Room> room_itr = rooms.getAllRooms().iterator();
		while (room_itr.hasNext()) {
			Room room = room_itr.next();
			System.out.println("[CHECK STATUS] Room: " + room.getRoomProperties().name + " -> " + room.getClients());
		}
		
		List<String> streams = app.getBroadcastStreamNames(app.getScope());
		Iterator<String> stream_itr = streams.iterator();

		System.out.println("----");
		System.out.println("[CHECK STATUS] Streams open: " + streams.size());
		while (stream_itr.hasNext()) {
			System.out.println("[CHECK STATUS] Stream: " + stream_itr.next());
		}
		
		System.out.println("");
		
		/*
		Iterator<IConnection> itr = this.app.getConnections();
		while (itr.hasNext()) {
			IServiceCapableConnection service = (IServiceCapableConnection) itr.next();
			
			User user = new User();
			user.firstName = "Dan";
			user.lastName = "Schultz";
			
			service.invoke("addUser", new Object[] { user });
		}
		*/
		
	}
	
}
